package admin_api

import (
	"github.com/gin-gonic/gin"
	"shop/admin/admin_service"
	"shop/entity"
	"shop/utils/convertutil"
	"shop/utils/result"
)

func GetSysUserList(c *gin.Context) {
	result.RenderResult(c, admin_service.GetSysUserList())
}

func AddSysUser(c *gin.Context) {
	sysUser := new(entity.SysUser)
	if err := c.ShouldBindJSON(sysUser); err != nil {
		result.RenderFail(c, "参数格式错误："+err.Error())
		return
	}

	result.RenderResult(c, admin_service.AddSysUser(sysUser))
}

func UpdateSysUser(c *gin.Context) {
	sysUser := new(entity.SysUser)
	if err := c.ShouldBindJSON(sysUser); err != nil {
		result.RenderFail(c, "参数格式错误："+err.Error())
		return
	}

	result.RenderResult(c, admin_service.UpdateSysUser(convertutil.ParseInt64(c.Param("id")), sysUser))
}

func DeleteSysUser(c *gin.Context) {
	id := convertutil.ParseInt(c.Param("id"))
	result.RenderResult(c, admin_service.DeleteSysUser(id))
}
